<template>
  <div>
    <el-table :data="bannerList" border style="width: 100%">
      <el-table-column prop="id" label="编号">
      </el-table-column>
      <el-table-column prop="title" label="轮播图标题" width="180">
      </el-table-column>
      <el-table-column label="图片">
        <template slot-scope="item">
          <div>
            <img :src="item.row.img" alt="" class="img">
          </div>
        </template>
      </el-table-column>
      <el-table-column prop="address" label="状态">
        <template slot-scope="item">
          <div>
            <el-tag type="success" plain v-if="item.row.status == 1" size="medium ">启用</el-tag>
            <el-tag type="danger" plain v-else size="medium ">禁用</el-tag>
          </div>
        </template>
      </el-table-column>
      <el-table-column prop="address" label="操作">
      <template slot-scope="item">
        <div>
          <el-button type="primary" @click="edit(item.row.id)">编辑</el-button>
        <el-button type="danger" @click="del(item.row.id)">删除</el-button>
        </div>
      </template>
      </el-table-column>

    </el-table>
  </div>
</template>
<script>
import { bannerdelete } from "../../request/api"
import { mapGetters, mapActions } from 'vuex';
export default {
  data() {
    return {

    }
  },
  methods: {
    ...mapActions({
      getBanner: "banner/getBannerListAction"
    }),
    edit(id) {
      this.$emit("edit", id)
    },
    del(id) {
      bannerdelete({ id }).then(res => {
        // console.log(res);
        if (res.code == 200) {
          this.$store.dispatch("banner/getBannerListAction")
          this.$message({
            type: 'success',
            message: '删除成功!'
          });
        } else {
          this.$message({
            type: 'error',
            message: res.msg
          });
        }
      })

    }


  },
  mounted() {
    this.getBanner()

  },
  watch: {},
  computed: {
    ...mapGetters({
      bannerList: "banner/getBanner"
    })
  },
  filters: {},
  components: {}
}
</script>
<style scoped>
.img {
  width: 100px;
}
</style>